package com.peng.ivos.application.controller;

import com.peng.ivos.application.pojo.dto.ApplicationQuery;
import com.peng.ivos.application.pojo.dto.ApplicationSaveParam;
import com.peng.ivos.application.service.ApplicationService;
import com.peng.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 申请模块控制层
 * @author： Peng
 * @date： 2024/5/24
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/application")
@Slf4j
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @PostMapping("/save")
    public JsonResult addApplication(ApplicationSaveParam applicationSaveParam){
        log.info("提交申请，applicationSaveParam:{}", applicationSaveParam);
        return applicationService.addApplication(applicationSaveParam);
    }

    @GetMapping("/select")
    public JsonResult getApplicationList(ApplicationQuery applicationQuery){
        log.debug("查询申请列表，applicationQuery:{}", applicationQuery);
        return applicationService.getApplicationList(applicationQuery);
    }

    @PostMapping("/cancel/{id}")
    public JsonResult cancelApplication(@PathVariable("id") Long applicationId){
        log.debug("取消申请，applicationId:{}", applicationId);
        return applicationService.cancelApplication(applicationId);
    }

    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distributeVehicle(@PathVariable("applicationId") Long applicationId, @PathVariable("vehicleId") Long vehicleId){
        log.debug("分配车辆，applicationId:{}，vehicleId:{}", applicationId, vehicleId);
        return applicationService.distributeVehicle(applicationId, vehicleId);
    }

    @PostMapping("/back/{applicationId}/{vehicleId}")
    public JsonResult backVehicle(@PathVariable("applicationId") Long applicationId, @PathVariable("vehicleId") Long vehicleId){
        log.debug("归还车辆，applicationId:{}，vehicleId:{}", applicationId, vehicleId);
        return applicationService.backVehicle(applicationId, vehicleId);
    }


}
